/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketmaster.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.RowSet;
import ticketmaster.dataobject.PremiumCustomerReward;

/**
 *
 * @author Wei Liu
 */
public class PremiumCustomerRewardDAO extends BaseEntityDAO
{
    public PremiumCustomerRewardDAO()
    {
        // initialization
    }

    /**
     * Insert premiumCustomerReward into database
     * @param premiumCustomerReward the new premiumCustomerReward entity to be inserted
     * @return newly created premiumCustomerReward number or a 0 on error
     */
    public int insertPremiumCustomerReward(PremiumCustomerReward premiumCustomerReward)
    {
        return save(premiumCustomerReward);
    }

    /**
     * Delete premiumCustomerReward that matches the supplied criteria
     * @param premiumCustomerReward the supplied criteria
     * @return true on success, false on failure
     */
    public boolean deletePremiumCustomerReward(PremiumCustomerReward premiumCustomerReward)
    {
        return delete(premiumCustomerReward);
    }

    /**
     * Update the premiumCustomerReward using data from the premiumCustomerReward Data Object
     * @param premiumCustomerReward the premiumCustomerReward Data Object to be updated
     * @return true on success, false on failure or error
     */
    public boolean updatePremiumCustomerReward(PremiumCustomerReward premiumCustomerReward)
    {
        if (premiumCustomerReward.getCustomerID() == 0 || premiumCustomerReward.getRewardID() == 0)
        {
            return false;
        }

        if (update(premiumCustomerReward))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * Get the premiumCustomerReward that matches the supplied criteria
     * @param premiumCustomerReward the supplied criteria
     * @return a Data Object if found, or null on error or if not found
     */
    public PremiumCustomerReward findPremiumCustomerReward(PremiumCustomerReward premiumCustomerReward)
    {
        String sql = null;

        if (premiumCustomerReward.getCustomerID() != 0 && premiumCustomerReward.getRewardID() != 0)
        {
            sql = buildQuerySQL(premiumCustomerReward);
        }
        else
        {
            return null;
        }

        RowSet crs = query(sql);
        try
        {
            crs.next();
        }
        catch (SQLException ex)
        {
            Logger.getLogger(PremiumCustomerRewardDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return (PremiumCustomerReward) this.getObject(crs, premiumCustomerReward);
    }

    /**
     * Get all premiumCustomerRewards that match the supplied criteria
     * @param premiumCustomerReward supplied criteria
     * @return a RowSet
     */
    public RowSet getPremiumCustomerRewardsRS(PremiumCustomerReward premiumCustomerReward)
    {
        String sql = buildQuerySQL(premiumCustomerReward);
        return query(sql);
    }

    /**
     * Get all premiumCustomerRewards that match the supplied criteria
     * @param premiumCustomerReward supplied criteria
     * @return a collection of PremiumCustomerReward Data Objects
     */
    public Collection<PremiumCustomerReward> getPremiumCustomerRewardsDO(PremiumCustomerReward premiumCustomerReward)
    {
        String sql = buildQuerySQL(premiumCustomerReward);

        RowSet crs = query(sql);
        Collection<PremiumCustomerReward> premiumCustomerRewards = new ArrayList<PremiumCustomerReward>();
        try
        {
            while (crs.next())
            {
                PremiumCustomerReward premiumCustomerRewardDO = (PremiumCustomerReward) this.getObject(crs, premiumCustomerReward);
                PremiumCustomerReward item = new PremiumCustomerReward();
                item.setCustomerID(premiumCustomerRewardDO.getCustomerID());
                item.setRewardID(premiumCustomerRewardDO.getRewardID());
                item.setDate(premiumCustomerRewardDO.getDate());
                premiumCustomerRewards.add(item);
            }
        }
        catch (SQLException ex)
        {
            Logger.getLogger(PremiumCustomerRewardDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return premiumCustomerRewards;
    }
}
